import Vue from 'vue'
import './cube-ui'
import App from './App.vue'
import { sendPost, sendGet, sendUpload, put, del, handleError } from './util/request'
import { entry } from './util/entry'
import 'amfe-flexible'
import 'animate.css'
import router from './router'
import VueLazyload from 'vue-lazyload'
import '@/assets/fonts/iconfont.css'
import '@/assets/fonts/iconfont.js'
import store from './store'


// 设置微信操作对象
if(process.env.NODE_ENV === 'production'){
  Vue.prototype.$wx = window.wx
  // 隐藏非必要按钮
  window.wx.hideAllNonBaseMenuItem()
  window.wx.showMenuItems({
    menuList: ["menuItem:share:appMessage","menuItem:share:timeline","menuItem:favorite"]
  })
}


Vue.config.productionTip = false
Vue.config.ignoredElements = ['wx-open-subscribe']

Vue.prototype.$sendPost = sendPost
Vue.prototype.$sendGet = sendGet
Vue.prototype.$sendUpload = sendUpload
Vue.prototype.$put = put
Vue.prototype.$del = del
Vue.prototype.$handleError = handleError

// 图片懒加载
Vue.use(VueLazyload)

const VUE = new Vue({
    router,
    store,
    render: h => h(App)
})

async function run() {
    try {
        await entry()
        VUE.$mount('#app')
        document.querySelector('#before').remove()
    }catch (e) {
        let before = document.querySelector('#before')
        before.querySelector('.logining').remove()
        before.querySelector('.login-error h2').innerHTML = e.data.message
        before.querySelector('.login-error').style.display = 'block'
        before.querySelector('.login-error').onclick = function() {
            window.location.reload()
        }
    }
}
run()
